//使用策略模式对多种相似业务进行处理
interface VipRechargeSrategy {
    recharge(priceCode: string): void
}

class OneMonthVipStrategy implements VipRechargeSrategy {
    recharge(priceCode: string): void {
        console.log(`priceCode:${priceCode} 充值一个月会员到账`)
    }
}

class ThreeMonthVipStrategy implements VipRechargeSrategy {
    recharge(priceCode: string): void {
        console.log(`priceCode:${priceCode} 充值三个月会员到账`)

    }
}

class YearMonthVipStrategy implements VipRechargeSrategy {
    recharge(priceCode: string): void {
        console.log(`priceCode:${priceCode} 充值一年会员到账`)
    }
}

//使用单例模式返回唯一工厂实例，使用工厂实例返回不同策略
class VipRechargeFactory {
    public static readonly readonlyMap: ReadonlyMap<string, VipRechargeSrategy> = new Map([
        ["2001", new OneMonthVipStrategy()],
        ["2002", new ThreeMonthVipStrategy()],
        ["2003", new YearMonthVipStrategy()]
    ])

    public static SingletonHolder = class InnerSingletonHolder {
        public static vipRechargeFactory: VipRechargeFactory = new VipRechargeFactory()
    }

    public static getInstance(): VipRechargeFactory {
        return VipRechargeFactory.SingletonHolder.vipRechargeFactory;
    }

    public getConcreateStrategy(priceCode: string): VipRechargeSrategy | undefined {
        return VipRechargeFactory.readonlyMap.get(priceCode)
    }
}

const test = () => {
    const priceCode:string = "2003"
   const strategy :VipRechargeSrategy | undefined = VipRechargeFactory.getInstance().getConcreateStrategy(priceCode)
   if(!strategy){
    console.log(`策略不符合`);
       return ; 
   }
   strategy.recharge(priceCode)
}
test()